package cn.ac.aircas.common.utils;

import cn.ac.aircas.common.constant.CacheConstants;
import cn.ac.aircas.common.core.redis.RedisCache;
import cn.ac.aircas.common.utils.spring.SpringUtils;

import java.util.Collection;

public class RoadUtils {
    /**
     * 设置cache key
     *
     * @param configKey 参数键
     * @return 缓存键key
     */
    public static String getUnderCacheKey(String configKey) {
        return CacheConstants.UNDERGROUND + configKey;
    }

    /**
     * 设置cache key
     *
     * @param configKey 参数键
     * @return 缓存键key
     */
    public static String getGroundCacheKey(String configKey) {
        return CacheConstants.GROUND + configKey;
    }

    /**
     * 清空字典缓存
     */
    public static void clearUnderCache() {
        Collection<String> keys = SpringUtils.getBean(RedisCache.class).keys(CacheConstants.UNDERGROUND + "*");
        SpringUtils.getBean(RedisCache.class).deleteObject(keys);
    }

    /**
     * 清空字典缓存
     */
    public static void clearGroundCache() {
        Collection<String> keys = SpringUtils.getBean(RedisCache.class).keys(CacheConstants.GROUND + "*");
        SpringUtils.getBean(RedisCache.class).deleteObject(keys);
    }
}
